/**************************************************************************
	fsHouse - Gateway
	Version 1.0
***************************************************************************/
#include "bconf/inSketch.h"
#include "fshSoulissCommon.h"

// Activate the define for sketch debugging
/*
#define SKETCH_DEBUG
#define VNET_DEBUG_INSKETCH
#define VNET_DEBUG    1
#define MaCaco_DEBUG_INSKETCH
#define MaCaco_DEBUG  1
*/
#define	QC_BOARDTYPE				0x04
#define	QC_GATEWAYTYPE			0x01
#define	QC_INTERFACE				0x00
#define DYNAMICADDRESSING  	0x01

#include "Souliss.h"
#include "SpeakEasy.h"
#include <SPI.h>

#include "fshSoulissNetwork.h"			// fsHome common definitions

// Global Variables

// Network address
uint8_t ip_address[4]  = {IP_ADDRESS_1, IP_ADDRESS_2, IP_ADDRESS_3, IP_ADDRESS_4_SOUGW};

void setup()
{
	#ifdef SKETCH_DEBUG
	Serial.begin(9600);
	#endif
	
	// Setup the network configuration	
	Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
	Souliss_SetLocalAddress(memory_map, (U16)ip_address[3]);

	vNet_SetRoutingTable(IP_ADDRESS_R1B1, RS485_ADDRESS_R1B1, 0);
	vNet_SetRoutingTable(IP_ADDRESS_R2B1, RS485_ADDRESS_R2B1, 1);
	// vNet_SetRoutingTable(IP_ADDRESS_R3B1, RS485_ADDRESS_R3B1, 2);
	// vNet_SetRoutingTable(IP_ADDRESS_R4B1, RS485_ADDRESS_R4B1, 3);
	vNet_SetSubnetMask(SOULISS_SUBNET_MASK, 5);

	// Init the openHAB HTTP/XML Interface
	#if (QC_INTERFACE == 0x02)
	XMLSERVERInit(memory_map);
	#endif
}

void loop()
{
	EXECUTEFAST() {	
		UPDATEFAST();
		
		FAST_GatewayComms();
/*
		FAST_210ms() {   
			#if (QC_INTERFACE == 0x02)
			XMLSERVERInterface(memory_map);		
			#endif
		}
*/
	}
}
